
const state = {
  sourceList: [],//原始数据
  mapList: [
    {
      name: 'avro',
      parameters: [
        {
          defaultValue: '',
          name: 'schema.def',
          optional: false
        },
        {
          defaultValue: '',
          name: 'schema.registry',
          optional: false
        },
        {
          defaultValue: '',
          name: 'schema.id',
          optional: false
        },
        {
          defaultValue: '',
          name: 'fail.on.missing.attribute',
          optional: true,
          isCheck: false
        },
      ]
    },
    {
      name: 'binary',
      parameters: []
    },
    {
      name: 'csv',
      parameters: [
        {
          defaultValue: '',
          name: 'delimiter',
          optional: true
        },
        {
          defaultValue: '',
          name: 'header.present',
          optional: true
        },
        {
          defaultValue: '',
          name: 'fail.on.unknown.attribute',
          optional: true
        },
        {
          defaultValue: '',
          name: 'event.grouping.enabled',
          optional: true
        },
      ]
    },
    {
      name: 'json',
      parameters: [
        {
          defaultValue: '',
          name: 'enclosing.element',
          optional: true
        },
        {
          defaultValue: '',
          name: 'fail.on.missing.attribute',
          optional: true
        },
      ]
    },
    {
      name: 'keyvalue',
      parameters: [
        {
          defaultValue: '',
          name: 'fail.on.missing.attribute',
          optional: true
        },
      ]
    },
    {
      name: 'passThrough (default)',
      parameters: [

      ]
    },
    {
      name: 'text',
      parameters: [
        {
          defaultValue: '',
          name: 'regex.groupid',
          optional: false
        },
        {
          defaultValue: '',
          name: 'fail.on.missing.attribute',
          optional: true
        },
        {
          defaultValue: '',
          name: 'event.grouping.enabled',
          optional: true
        },
        {
          defaultValue: '',
          name: 'delimiter',
          optional: true
        },
        {
          defaultValue: '',
          name: 'new.line.character',
          optional: true
        },
      ]
    },
    {
      name: 'xml',
      parameters: [
        {
          defaultValue: '',
          name: 'namespaces',
          optional: true
        },
        {
          defaultValue: '',
          name: 'enclosing.element',
          optional: true
        },
        {
          defaultValue: '',
          name: 'enclosing.element.as.event',
          optional: true
        },
        {
          defaultValue: '',
          name: 'fail.on.missing.attribute',
          optional: true
        },
      ]
    },
  ],
  mapParameters: []

}
const mutations = {
  setSource: (state, data) => {
    data.sort((a, b) => a.optional - b.optional)
    state.sourceList = data
  },
  setMap: (state, data) => {
    data.sort((a, b) => a.optional - b.optional)
    state.mapParameters = data
  },

}

const actions = {
  getMap({ state, commit, rootState }, name) {
    const mapList = state.mapList
    const data = mapList.find(item => item.name == name)?.parameters || []

    commit('setMap', data)
  },
  getSource({ state, commit, rootState }, name) {
    const sources = rootState.projection.metadata.extensions.source.sources
    const data = sources.find(item => item.name == name)?.parameters || []
    commit('setSource', data)
  },
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  // getters
}
